package com.mall.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.model.GlobalResponse;
import com.mall.service.IProductService;
import com.mall.vo.ProductDetailVO;
import com.mall.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {
    @Autowired
    private IProductService productService;

    @GetMapping("/products")
    public GlobalResponse<PageInfo<ProductVO>> list(@RequestParam(required = false) Integer categoryId,
                                                    @RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                                    @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        return productService.list(categoryId,pageNum,pageSize);
    }

    @GetMapping("/products/{productId}")
    public GlobalResponse<ProductDetailVO> detail(@PathVariable Integer productId){
        return productService.detail(productId);
    }
}
